#!/bin/bash

function generate_shift_cmd {
    SRC_FILE=$1
    RES_FILE=$2
    MX_PARTS=$3
    WIN_LEN=$4
    REWARD=$5
    PENALTY=$6

    echo "\"cat $SRC_FILE | ./make_shifts_hard.py | ./find_shifts.py -l $WIN_LEN -p $PENALTY -r $REWARD -m $MX_PARTS > ${RES_FILE}\""
}

function generate_noshift_cmd {
    SRC_FILE=$1
    RES_FILE=$2
    MX_PARTS=$3
    WIN_LEN=$4
    REWARD=$5
    PENALTY=$6

    echo "\"cat $SRC_FILE | ./find_shifts.py -l $WIN_LEN -p $PENALTY -r $REWARD -m $MX_PARTS > ${RES_FILE}\""
}

function generate_cmd {
    SRC_FILE=$1
    PREFIX=$2
    MX_PARTS=$3
    WIN_LEN=$4
    REWARD=$5
    PENALTY=$6

    RES_DIR=results/${PREFIX}_${MX_PARTS}_${WIN_LEN}_${REWARD}_${PENALTY}
    mkdir -p $RES_DIR

    generate_noshift_cmd $SRC_FILE $RES_DIR/"noshift.txt" $MX_PARTS $WIN_LEN $REWARD $PENALTY
    generate_shift_cmd   $SRC_FILE $RES_DIR/"shift.txt"   $MX_PARTS $WIN_LEN $REWARD $PENALTY
}


function generate_full_cmd {
    SRC_RAND_FILE=$1
    SRC_ORIG_FILE=$2
    BASE_RES_DIR=$3
    MX_PARTS=$4
    WIN_LEN=$5
    REWARD=$6
    PENALTY=$7

    RES_DIR=${BASE_RES_DIR}/${MX_PARTS}_${WIN_LEN}_${REWARD}_${PENALTY}
    mkdir -p $RES_DIR

    generate_noshift_cmd $SRC_RAND_FILE $RES_DIR/"noshift.txt" $MX_PARTS $WIN_LEN $REWARD $PENALTY
    generate_shift_cmd   $SRC_RAND_FILE $RES_DIR/"shift.txt"   $MX_PARTS $WIN_LEN $REWARD $PENALTY
    generate_noshift_cmd $SRC_ORIG_FILE $RES_DIR/"orig.txt"    $MX_PARTS $WIN_LEN $REWARD $PENALTY
}


function gen1 {
    SRC_FILE=$1
    PREFIX=$2
    for MX_PARTS in 2; do
    #for MX_PARTS in 2 4; do
    #    for REWARD in 3 5 7 10 12; do
        for REWARD in 0 1 2 3; do
            for PENALTY in 800 1000 1200 1500 1700 2000; do
    #            for WIN_LEN in 60 120; do
                for WIN_LEN in 60; do
                    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN $REWARD $PENALTY
                done
            done
        done
    done 
}

function gen2 {
    SRC_FILE=$1
    PREFIX=$2
    MX_PARTS=2
    WIN_LEN=60

    for REWARD in 0 1 2 3; do
        for PENALTY in 1500 1700 2000; do
            generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN $REWARD $PENALTY
        done
    done

    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 5  1500
    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 7  1200
    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 7  1500
    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 10 800
    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 10 1000
    generate_cmd $SRC_FILE $PREFIX $MX_PARTS $WIN_LEN 10 1200
}

function gen3 {
    SRC_FILE=$1
    PREFIX=$2
    MX_PARTS=2
    WIN_LEN=60
    DST_FNAME="orig.txt"

    for REWARD in 0 1 2 3; do
        for PENALTY in 1500 1700 2000; do
            generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN $REWARD $PENALTY
        done
    done

    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 5  1500
    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 7  1200
    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 7  1500
    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 10 800
    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 10 1000
    generate_noshift_cmd $SRC_FILE $DST_FNAME $PREFIX $MX_PARTS $WIN_LEN 10 1200
}

function gen4 {
    SRC_RAND_FILE=$1
    SRC_ORIG_FILE=$2
    BASE_RES_DIR=$3
    for MX_PARTS in 2; do
        for REWARD in 3 5 7 10 12 15; do        
#        for REWARD in 1 3 5; do
#            for PENALTY in 800 1000 1200 1500 1700 2000; do
            for PENALTY in 100 300 500 1000; do
                for WIN_LEN in 60; do
                    generate_full_cmd $SRC_RAND_FILE $SRC_ORIG_FILE $BASE_RES_DIR $MX_PARTS $WIN_LEN $REWARD $PENALTY
                done
            done
        done
    done 
}

function gen5 {
    SRC_RAND_FILE=$1
    SRC_ORIG_FILE=$2
    BASE_RES_DIR=$3
    for MX_PARTS in 2; do
        for REWARD in 5; do
            for PENALTY in 500; do
                for WIN_LEN in 60; do
                    generate_full_cmd $SRC_RAND_FILE $SRC_ORIG_FILE $BASE_RES_DIR $MX_PARTS $WIN_LEN $REWARD $PENALTY
                done
            done
        done
    done
}

#gen1 data/e.coli.good.random.txt random | xargs -n1 -P6 -I {} sh -c '{}'
#gen2 data/e.coli.good.random.txt random_new | xargs -n1 -P8 -I {} sh -c '{}'

#gen2 data/e.coli.good.random.txt random_hard | xargs -n1 -P8 -I {} sh -c '{}'

#gen4 data/NC_007760.good.random.txt data/NC_007760.good.txt results/NC_007760 | xargs -n1 -P8 -I {} sh -c '{}'

#gen5 data/NC_007760.good.random.txt data/NC_007760.good.txt results/NC_007760.mk \
#    | sed 's/find_shifts/find_shifts_mk/g' \
#    | xargs -n1 -P8 -I {} sh -c '{}'

#gen4 data/NC_007760.good.random.txt data/NC_007760.good.txt results/NC_007760.mk.light \
#        | sed 's/find_shifts/find_shifts_mk_light/g' \
#        | xargs -n1 -P7 -I {} sh -c '{}'

#gen4 data/NC_011353.good.random.txt data/NC_011353.good.txt results/NC_011353.mk.light \
#    | sed 's/find_shifts/find_shifts_mk_light/g' \
#    | xargs -n1 -P7 -I {} sh -c '{}'

gen4 data/NC_011353.good.random.txt data/NC_011353.good.txt results/NC_011353.mk.max \
    | sed 's/find_shifts.py/"find_shifts_mk_max.py -v"/g' \
    | xargs -n1 -P7 -I {} sh -c '{}'


